/**
 * skyme
 */

package com.aliyun.shell;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * The Class Shell.
 *
 * @author zhangfeng
 */
public class Shell {
	
	/**
	 * Ec.
	 *
	 * @param command the command
	 * @return the string
	 * @throws InterruptedException the interrupted exception
	 */
	public static String ec(String command) throws InterruptedException {
		String returnString = "";
		Process pro = null;
		Runtime runTime = Runtime.getRuntime();
		if (runTime == null) {
			System.err.println("Create runtime false!");
		}
		try {
			pro = runTime.exec(command);
			BufferedReader input = new BufferedReader(new InputStreamReader(
					pro.getInputStream()));
			PrintWriter output = new PrintWriter(new OutputStreamWriter(
					pro.getOutputStream()));
			String line;
			while ((line = input.readLine()) != null) {
				// System.out.println(line);
				returnString = returnString + line + "\n";
			}
			input.close();
			output.close();
			pro.destroy();
		} catch (IOException ex) {
			Logger.getLogger(Shell.class.getName()).log(Level.SEVERE, null, ex);
		}
		return returnString;
	}
}
